import 'package:star_author/utils/common_util/date_util.dart';
import 'package:star_author/utils/utils.dart';
import 'package:star_author/widgets/dialog/get_dialog.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

//todo:转回流信息组件
class BackflowGoodWidget extends StatelessWidget {
  Map param;
  BackflowGoodWidget({
    Key? key,
    this.param: const {},
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Text(
              '转回流信息',
              style: TextStyle(
                color: rgba(153, 153, 153, 1),
                fontSize: 12.sp,
              ),
            ),
            SizedBox(
              width: 3.w,
            ),
            Image(
              image: AssetImage('images/lt_common/right_arrow.png'),
              width: 6.w,
            ),
          ],
        ),
      ),
      onTap: () {
        showGetDialog(
          LastBackflowGoodInfo(
            param: param,
          ),
          barrierDismissible: true,
          margin: 45.w,
        );
      },
      behavior: HitTestBehavior.opaque,
    );
  }
}

class LastBackflowGoodInfo extends StatelessWidget {
  Map param;
  LastBackflowGoodInfo({
    Key? key,
    this.param: const {},
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    double? num = double.tryParse(param['order_price'].toString());
    print("ss--:${param}");
    String price = "";
    if (num != null) {
      if (num % 1 == 0) {
        price = num.toInt().toString();
      } else {
        price = num.toString();
      }
    }
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.w),
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          SizedBox(
            height: 20.w,
          ),
          Center(
            child: Text(
              "原回流信息",
              style: TextStyle(
                color: rgba(50, 50, 50, 1),
                fontSize: 16.sp,
                fontWeight: FontWeight.w500,
              ),
            ),
          ),
          SizedBox(
            height: 20.w,
          ),
          buildRow('货品编号', param['serial'] ?? ""),
          buildRow(
            '源头市场价',
            getPriceWithList(
              param['price_range'] ?? [],
              intl: true,
            ).isEmpty
                ? "暂无市场价"
                : getPriceWithList(
                    param['price_range'] ?? [],
                    intl: true,
                  ),
          ),
          buildRow(
              '中拍价', (param['order_price'] ?? 0) == 0 ? "暂无中拍价" : "¥${price}"),
          buildRow('回流时间', DateUtil.formatDateStr(param['created_at'] ?? "")),
          Container(
            height: 1.w,
            width: Get.width,
            color: rgba(241, 241, 241, 1),
          ),
          GestureDetector(
            child: Container(
              height: 43.w,
              width: Get.width,
              child: Center(
                child: Text(
                  "关闭",
                  style: TextStyle(
                    color: rgba(254, 186, 7, 1),
                    fontSize: 16.sp,
                  ),
                ),
              ),
            ),
            behavior: HitTestBehavior.opaque,
            onTap: () {
              Get.back();
            },
          )
        ],
      ),
    );
  }

  Widget buildRow(String title, String value) {
    return Container(
      margin: EdgeInsets.only(
        bottom: 12.w,
        left: 12.w,
      ),
      child: Row(
        children: [
          Container(
            alignment: Alignment.centerLeft,
            width: 96.w,
            child: Text(
              title + "：",
              style: TextStyle(
                fontSize: 15.sp,
                color: rgba(153, 153, 153, 1),
              ),
            ),
          ),
          Text(
            value,
            style: TextStyle(
              color: rgba(51, 51, 51, 1),
              fontSize: 15.sp,
            ),
          ),
        ],
      ),
    );
  }
}
